<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>兑换码</title>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<link rel="stylesheet" type="text/css" href="css/aui.css" />
		<!--<script src="//s.url.cn/qqun/qun/qqweb/m/qun/confession/js/vconsole.min.js"></script>-->
	</head>
	<body>
		<div class="content" style="width: 100%;padding: 5rem 2rem;">
			<input type="text" name="" id="code" value="" style="background: #FFFFFF;border: 1px solid #E5E5E5;border-radius: 4px;height: 3.67rem;font-size: 1.5rem;color: #999999;text-indent: 1em;"placeholder="输入兑换码"/>
			<div id="btn" style="background: rgb(224,224,224);border-radius: 4px;height: 4.17rem;width: 100%;margin-top: 3.67rem;margin-bottom: 2rem;font-size: 1.833rem;line-height: 4.17rem;text-align: center;color: #FFFFFF;-webkit-tap-highlight-color:rgba(255,255,255,0)">兑换</div>
			<p style="color: #282828;font-size: 1.5rem;font-weight: 500;">使用说明</p>
			<p style="font-size: 1.2rem;">1、兑换码只能在“蜜读”平台使用</p>
			<p style="font-size: 1.2rem;">2、兑换码为一次性产品，不能重复使用</p>
			<p style="font-size: 1.2rem;">3、兑换成功后，在“书架”栏目查看课程信息</p>
		</div>
	    <div id="warn" style="background: rgba(0, 0, 0, 0.7);text-align: center;border-radius: 0.25rem;color: #ffffff;position: fixed;z-index: 3000;top: 45%;left: 50%;width: 8em;margin-left: -4em;height: 3rem;line-height: 3rem;display: none;font-size: 1.6rem;">请先登录！</div>
	    <div class="MD_alertView hide">
	        <div class="MD_blackView" style="position: fixed; top: 0; left: 0;width: 100%;height: 100%;z-index: 10000;background: rgba(38,38,38,0.66);"></div>
	        <div class="MD_bigView" style="background-color: white; position: fixed; left: 15%; width: 70%; height: auto; top: 20rem; border-radius: .8rem; z-index: 10001;">
		        <p class="alert_title" align="center" style="font-size: 1.7rem; color: #333333; font-weight: bold;margin: 2rem 1.5rem 0.5rem 1.5rem;"></p>
		        <p class="alert_des" align="center" style="font-size: 1.3rem; color: #666666;margin: 0 1.5rem 2.0rem 1.5rem;"></p>
		        <div style="background-color: #EEEEEE;width: 100%;left: 0;height: 0.1rem;"></div>
		        <div class="saveBtn" align="center" style="left: 0; width: 100%; font-size: 1.5rem; height: 4.5rem; color: rgb(2,86,234); padding-top: 1.1rem;"></div>
	        </div>
       </div>
	</body>
</html>
<script src="js/wxrem.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-1.11.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/md5.js" type="text/javascript" charset="utf-8"></script>
<script src="js/art-template.js" type="text/javascript" charset="utf-8"></script>
<script src="js/purl.js" type="text/javascript" charset="utf-8"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	var MD_type;
	$('.MD_alertView').hide();
	$("#code").bind('input porpertychange',function(){
		if($(this).val().length==0){
			$("#btn").css('background','rgb(224,224,224)');
		}else{
			$("#btn").css('background','#ED8434');
		}
	});
	
	var updateUserInfo = function(){
		
	};
	getToken(updateUserInfo);
	
	$("#btn").click(function(){
		if ($("#code").val().length) {
			var url = ascli(hostUrl+"order/cdkey?token="+token+"&cdkey="+$("#code").val()+'&channel=weixin');
			$.ajax({
				type:"get",
				url:url,
				async:true,
				success:function(data){
					if (data.status == 0) {//成功
						if (data.data == 7) {//会员
							updateVIPData();
						} else{//主题
							createAlertView("兑换成功","可永久回看，终身学习","立即查看",1);
						}
					} else{//失败
						weekTip(data.message)
					}
				},
				error: function(){
					weekTip("兑换失败!")
				}
			})
		}
	});
	
	var updateVIPData = function(){
		$.ajax({
			type:"get",
			url:hostUrl + 'product/vip/get?openId=' + openId,
			async:true,
			success: function(data){
				if (!data.data) {
					return;
				}
				userVip = data.data;
				var weixinData=JSON.parse(sessionStorage.getItem('weixinData'));
				weixinData.data.vip=userVip;
				sessionStorage.setItem('weixinData',JSON.stringify(weixinData))
				window.sessionStorage.setItem('userVip',JSON.stringify(userVip))
				createAlertView("兑换成功","会员期内，每邀请一位好友加入，你的会员期限可延长7天（奖励不设上限）","开始听书",7);
			}
		});
	}
	
	function createAlertView(titleStr,des,btn,type){
    	    MD_type = type;
    	    $('.MD_alertView').show();
		$('.alert_title').text(titleStr);
		$('.alert_des').text(des);
		$('.saveBtn').text(btn);
	}
	
	$('.saveBtn').click(function(){
		$('.MD_alertView').hide();
		if (MD_type == 1) {//主题
			location.href="mine.html"
		}else {//会员
			location.href="index.html"
		}
	})
	
	$('.MD_blackView').click(function(){
		$('.MD_alertView').hide();
	})
</script>
